using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace GURUCORE.FormBase
{
	/// <summary>
	/// Summary description for DataInput.
	/// </summary>
	public class DataInput : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.Label lblCaption;
		private System.Windows.Forms.TextBox txtValue;
		private System.Windows.Forms.ToolTip tipDescription;
		private System.ComponentModel.IContainer components;

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.txtValue = new System.Windows.Forms.TextBox();
			this.lblCaption = new System.Windows.Forms.Label();
			this.tipDescription = new System.Windows.Forms.ToolTip(this.components);
			this.SuspendLayout();
			// 
			// txtValue
			// 
			this.txtValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtValue.Location = new System.Drawing.Point(104, 0);
			this.txtValue.Name = "txtValue";
			this.txtValue.Size = new System.Drawing.Size(136, 20);
			this.txtValue.TabIndex = 0;
			this.txtValue.Text = "";
			// 
			// lblCaption
			// 
			this.lblCaption.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.lblCaption.Location = new System.Drawing.Point(0, 0);
			this.lblCaption.Name = "lblCaption";
			this.lblCaption.Size = new System.Drawing.Size(100, 20);
			this.lblCaption.TabIndex = 1;
			this.lblCaption.Text = "[No caption]";
			this.lblCaption.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// tipDescription
			// 
			this.tipDescription.AutoPopDelay = 5000;
			this.tipDescription.InitialDelay = 100;
			this.tipDescription.ReshowDelay = 100;
			this.tipDescription.ShowAlways = true;
			// 
			// DataInput
			// 
			this.Controls.Add(this.txtValue);
			this.Controls.Add(this.lblCaption);
			this.Font = new System.Drawing.Font("Arial", 8.25F);
			this.Name = "DataInput";
			this.Size = new System.Drawing.Size(256, 20);
			this.ResumeLayout(false);

		}
		#endregion



		const int DEFAULT_WIDTH = -1;

		private int m_nCaptionPreferWidth = DEFAULT_WIDTH;
		/// <summary>
		/// Caption Label width will be set to this property's value  if this property is not set (default == 0)
		/// </summary>		
		public int CaptionPreferWidth
		{
			get
			{
				return m_nCaptionPreferWidth;
			}
			set
			{
				m_nCaptionPreferWidth = value;
			}
		}

		private int m_nTextBoxPreferWidth = DEFAULT_WIDTH;
		/// <summary>
		/// Value Textbox width will be set to this property's value  if this property is not set (default == 0)
		/// </summary>		
		public int TextBoxPreferWidth
		{
			get
			{
				return m_nTextBoxPreferWidth;
			}
			set
			{
				m_nTextBoxPreferWidth = value;
			}
		}




		private string m_sCaption;
		/// <summary>
		/// Caption of the data element
		/// </summary>
		public string Caption
		{
			get
			{
				return m_sCaption;
			}
			set
			{
				m_sCaption = value;
			}
		}

		private string m_sDefaultValue;
		/// <summary>
		/// DefaultValue of the TextBox will display
		/// </summary>
		public string DefaultValue
		{
			get
			{
				return m_sDefaultValue;
			}
			set
			{
				m_sDefaultValue = value;
			}
		}

		private string  m_sDescription;
		/// <summary>
		/// Description of will display when hover on Caption
		/// </summary>
		public string Description
		{
			get
			{
				return m_sDescription;
			}
			set
			{
				m_sDescription = value;
			}
		}


		public string Value
		{
			get
			{
                return txtValue.Text;
			}
		}




		public DataInput()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}


		private void SetupControlDecoration()
		{
			// TODO: set caption width
			if(m_nCaptionPreferWidth > DEFAULT_WIDTH)
			{
				lblCaption.Width = m_nCaptionPreferWidth;				
			}
			// TODO: set textbox width
			if(m_nTextBoxPreferWidth > DEFAULT_WIDTH)
			{
				txtValue.Width = m_nTextBoxPreferWidth;				
			}

			// TODO: setup description when hover on Caption
            tipDescription.SetToolTip(lblCaption, m_sDescription);
		}
	}
}
